#!/usr/bin/env bash

block="
server {
    listen 80;
    server_name $1;
    error_log /var/log/nginx/error.$1.log warn;
    set \$rootdir '$2';
    set \$indexfile '$6';

    root  \$rootdir;
    location / {
        index \$indexfile;
        try_files \$uri \$uri/ /\$indexfile?\$query_string;
    }

    location ~ \\.php$ {
        root  \$rootdir; 
	fastcgi_pass  unix://run/php-fpm/php-fpm.sock;
        fastcgi_index   \$indexfile;
        fastcgi_param   SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\\.php)(/.+)$;
        include         fastcgi_params;
    }
}
"


echo "$block" > "/etc/nginx/conf.d/$1.conf"
